/*
 * @author: wizardc
 */

using Dou.ScreenController;
using UnityEditor;
using UnityEngine;

namespace DouEditor.ScreenController
{
    [CustomEditor(typeof(ActiveAdapter))]
    public class ActiveAdapterEditor : Editor
    {
        private ActiveAdapter _target;
        private GameObject _gameObject;
        
        private void OnEnable()
        {
            _target = (ActiveAdapter) target;
            _gameObject = _target.gameObject;

            var uiScreenMode = ScreenControllerMgr.GetScreenMode();
            var uiFineTuningMode = ScreenControllerMgr.GetFineTuningMode();
            
            _target.isActive.Init(uiScreenMode, uiFineTuningMode, _gameObject.activeSelf);
        }
        
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            ScreenControllerMgr.DrawScreenModeLabel();
            
            var uiScreenMode = ScreenControllerMgr.GetScreenMode();
            var uiFineTuningMode = ScreenControllerMgr.GetFineTuningMode();
            
            _target.isActive.Record(uiScreenMode, uiFineTuningMode, _gameObject.activeSelf);
            
            serializedObject.ApplyModifiedProperties();
        }
    }
}
